package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;
import Models.POSSaleTab;

public class POSSaleTabPresenter extends AbstractPresenter<POSSaleTab> {
	final String SINGLEITEM = "posSaleTab";
	final String MULTIITEM = "pOSSaleTabs";
	
	public ArrayList<POSSaleTab> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public POSSaleTab tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public POSSaleTab createItemFromJSONObject(JSONObject jsonDiscount){
		POSSaleTab saleTab = new POSSaleTab();
		try{
			saleTab.setDescription(jsonDiscount.getString("description"));
			saleTab.setTabAmount(jsonDiscount.getInt("tabAmount"));
			saleTab.setId(jsonDiscount.getInt("id"));
			return saleTab;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(POSSaleTab item){
		try{
			JSONObject json = new JSONObject();
			json.put("description", item.getDescription());
			json.put("id", item.getId());
			json.put("tabAmount", item.getTabAmount());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public POSSaleTab getEmptyEntity(){
		POSSaleTab entity = new POSSaleTab();
		return entity;
	}
}
